class IUP_CLIPBOARD

inherit
	ANY

create {IUP_INTERFACE}
   init

feature {IUP_INTERFACE}
	
	init (interface: IUP_INTERFACE)
		-- Init the interface system
		do
			--io.put_string("Create Clipboard %N")
			int := interface.iup_open
		end
	
feature {ANY}

	clean
		-- Clears the clipboard data.
		local
			p: POINTER
		do
			p := int_clipboard
			int.set_attribute_null_in_handle(p, "TEXT")
			int_destroy(p)
		end

	is_text_available: BOOLEAN
		-- Informs if there is a text available at the clipboard.
		local
			p: POINTER
			s: STRING
		do
			p := int_clipboard
			s := int.get_attribute_from_handle(p, "TEXTAVAILABLE")
			int_destroy(p)

			if s.is_equal("YES") then
				Result := True
			else
				Result := False
			end
		end

	add_text (value: STRING)
		-- Copy text to the clipboard.
		local
			p: POINTER
		do
			p := int_clipboard
			int.set_attribute_in_handle(p, "TEXT", value)
			int_destroy(p)
		end

	get_text: STRING
		-- Paste text from the clipboard.
		local
			p: POINTER
			s: STRING
		do
			p := int_clipboard
			s := int.get_attribute_from_handle(p, "TEXT")
			int_destroy(p)

			Result := s
		end

feature {NONE}

	int: IUP

	int_clipboard: POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupClipboard()"
      end

	int_destroy (p: POINTER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"IupDestroy ($p);"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2018, 2019, 2020 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
